/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import com.sun.org.apache.bcel.internal.generic.AALOAD;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

/**
 *
 * @author rmb
 */
public class Client {
 
    private static DatagramSocket socket;
    private static Send send;
    private static Receive receive;
    private static FluxControl flux;
    public static long firstRTT;
    
    
        
      
    public static void main (String[] args) {
     
        try {
            socket = new DatagramSocket();
        }
        catch(SocketException e) {}
        
        
    }
     
    public Client() {
     
        try {
            socket = new DatagramSocket();
        }
        catch(SocketException e) {}
    }
    
    
    public static void initSend(String ip) {
        InetAddress addr = null;
        
        try {    
            addr = InetAddress.getByName(ip);
        }
        catch(UnknownHostException e) {}
        

        receive = new Receive(socket);
        receive.start();
        send = new Send(socket, addr);
    }
    
    public static void initFluxControl(){
        flux = new FluxControl(send.getToSend().size(),firstRTT);
        flux.start();
    }    
    
    public static void setFile(String filename) {
        try {
            send.setFile(filename);
        }
        catch(IOException e){}
    }


    public static void setWindowSize(int size){
        send.setWindow(size);
    }

    public static void sendPacks(){
        
        send.start();        
        
    }

    public static void endSend() {

        flux.stoprunning();
        receive.setFinished();
        send.stop();

        socket.close();
    }

    public static Send getSend(){
        return send;
    }

    public static Receive getRecieve(){
        return receive;
    }
    
    public static FluxControl getFluxControl(){
        return flux;
    }

    public static void unpause(){
        send.unpause();
    }

    public static void pauseSend() {
        send.pause();
    }

    public static void decreaseWindowsSize(){
        send.decreaseWindowSize();
    }

    public static void stopSend(){
        send.stop();
    }
    
    
}
